// poi-detail.js
const app = getApp();
const { pois } = require('../../utils/data.js');
const { getPoiTypeName } = require('../../utils/util.js');

Page({
  data: {
    poi: null,
    poiType: '',
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 500
  },

  onLoad: function (options) {
    const id = options.id;
    const poi = pois.find(p => p.id === id);
    
    if (poi) {
      this.setData({
        poi: poi,
        poiType: getPoiTypeName(poi.type)
      });
    } else {
      wx.showToast({
        title: '未找到该景点信息',
        icon: 'none'
      });
      
      setTimeout(() => {
        wx.navigateBack();
      }, 1500);
    }
  },

  // 导航到POI
  navigateToPoi: function() {
    const poi = this.data.poi;
    
    wx.openLocation({
      latitude: poi.position[1],
      longitude: poi.position[0],
      name: poi.name,
      address: poi.address || '',
      scale: 18
    });
  },

  // 预览图片
  previewImage: function(e) {
    const current = e.currentTarget.dataset.src;
    const urls = this.data.poi.images;
    
    wx.previewImage({
      current: current,
      urls: urls
    });
  }
}) 